package com.han.school.controller;

import com.han.school.pojo.User;
import com.han.school.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    @ResponseBody
    public String login(String uname,String pwd, HttpSession session) {
        User user = new User(uname,pwd);
        System.out.println(user);
        User userByName = userService.findUser(user);
        if (userByName != null) {
            session.setAttribute("user", userByName);
            return "1";
        } else {
            return "0";
        }
    }
}
